/*
 *   Copyright (c) 2010-2022, SIUFUNG
 */
package net.siufung.market.base.dept.controller.model.vo;

import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.siufung.core.model.AbstractVo;
import net.siufung.core.model.enums.DeletedEnum;
import net.siufung.market.base.dept.enums.DeptTypes;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * @author 陈建峰
 * @since 2022-07-13 22:40:52
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value="DeptVo", description="系统部门")
public class DeptVo extends AbstractVo {

    private static final long serialVersionUID = -1609268521114952585L;

    /**
     * 主键id
     */
    @ApiModelProperty(value = "主键id")
    private String id;

    /**
     * 部门名称
     */
    @ApiModelProperty(value = "部门名称")
    private String deptName;

    /**
     * 部门全称
     */
    @ApiModelProperty(value = "部门全称")
    private String deptFullName;

    /**
     * 部门名称
     */
    @ApiModelProperty(value = "部门名称")
    private String deptParentName;

    /**
     * 部门编码
     */
    @ApiModelProperty(value = "部门编码")
    private String deptCode;

    /**
     * 部门类型
     */
    @ApiModelProperty(value = "部门类型")
    private String deptType;

    /**
     * 父级ID
     */
    @ApiModelProperty(value = "父级ID")
    private String parentId;

    /**
     * 等级
     */
    @ApiModelProperty(value = "等级")
    private Integer level;

    /**
     * 排序
     */
    @ApiModelProperty(value = "排序")
    private Integer sequence;

    /**
     * 备注
     */
    @ApiModelProperty(value = "备注")
    private String description;

    /**
     * 租户
     */
    @ApiModelProperty(value = "租户")
    private Integer tenantId;

    /**
     * 创建人
     */
    @ApiModelProperty(value = "创建人")
    private String createdBy;

    /**
     * 创建时间
     */
    @ApiModelProperty(value = "创建时间")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    private LocalDateTime createdAt;

    /**
     * 更新人
     */
    @ApiModelProperty(value = "更新人")
    private String updatedBy;

    /**
     * 更新时间
     */
    @ApiModelProperty(value = "更新时间")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    private LocalDateTime updatedAt;

    /**
     * 数据标识
     */
    @ApiModelProperty(value = "数据标识")
    private Boolean deleted;

    /**
     * 子机构数量
     */
    @ApiModelProperty(value = "子机构数量")
    private Integer childCount;

    @Override
    public String getDeletedDesc() {
        return DeletedEnum.getDesc(deleted);
    }

    public String getDeptTypeDesc(){
        return DeptTypes.getDesc(deptType);
    }

    @Override
    public boolean getAllowRemove() {
        if(Objects.isNull(childCount)){
            return Boolean.FALSE;
        }
        return childCount == 0;
    }

    @Override
    public boolean getAllowUpdate() {
        return DeletedEnum.NOT.equals(DeletedEnum.get(deleted));
    }

}